package org.spring.springboot.app.platform.balancelog.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.springboot.app.agent.balancelog.domain.po.SysOfficeBalanceLogPO;
import org.spring.springboot.app.agent.balancelog.domain.vo.SysOfficeBalanceLogSearchVO;
import org.spring.springboot.app.platform.balancelog.dao.PlatformBalanceLogDao;
import org.spring.springboot.app.platform.balancelog.domain.po.PlatformBalanceLogPO;
import org.spring.springboot.app.platform.balancelog.domain.vo.*;
import org.spring.springboot.app.platform.balancelog.service.IPlatformBalanceLogService;
import org.spring.springboot.app.sys.dict.domain.vo.SysDictTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class PlatformBalanceLogServiceImpl implements IPlatformBalanceLogService {

    private static final Logger LOGGER = LoggerFactory.getLogger(PlatformBalanceLogServiceImpl.class);

    @Autowired
    private PlatformBalanceLogDao platformBalanceLogDao;


    @Override
    public PlatformBalanceLogPO find(String id) {
        return platformBalanceLogDao.selectByPrimaryKey(id);
    }

    @Override
    public List<PlatformBalanceLogPO> findPage(PlatformBalanceLogSearchVO searchvo, int pageNum, int pageSize, String types) {
        return platformBalanceLogDao.findPage(searchvo,pageNum,pageSize,types);
    }

    @Override
    public int save(PlatformBalanceLogPO po) {
        po.preInsert();
        return platformBalanceLogDao.insertSelective(po);
    }

    @Override
    public int update(PlatformBalanceLogPO po) {
        po.preUpdate();
        return platformBalanceLogDao.updateByPrimaryKeySelective(po);
    }

    @Override
    public int delete(String id) {
        PlatformBalanceLogPO po = new PlatformBalanceLogPO();
        po.setId(id);
        po.preDelete();
        return platformBalanceLogDao.updateByPrimaryKeySelective(po);
    }

    @Override
    public int deletes(String ids) {
        PlatformBalanceLogPO record = new PlatformBalanceLogPO();
        String[] id_s = ids.split(",");
        record.preDelete();
        int count = 0;
        for (String id : id_s) {
            record.setId(id);
            count += platformBalanceLogDao.updateByPrimaryKeySelective(record);
        }
        return count;
    }


    @Override
    public int addBalanceLog(BigDecimal mo, int type, String relateId, String relateExtId, String remark) {
        PlatformBalanceLogPO po = new PlatformBalanceLogPO();
        po.setMoney(mo);
        po.setType(type);
        po.setRelateId(relateId);
        po.setRelateExtId(relateExtId);
        po.setRemarks(relateExtId);
        po.preInsert();
        if(platformBalanceLogDao.insertSelective(po)<1){
            throw new RuntimeException("平台日志添加失败");
        }
        return 1;
    }

    @Override
    public String yesterdaySum() {
        return platformBalanceLogDao.yesterdaySum();
    }

    @Override
    public String lastweekSum() {
        return platformBalanceLogDao.lastweekSum();
    }

    @Override
    public String lastmonthSum() {
        return platformBalanceLogDao.lastmonthSum();
    }

    @Override
    public List<UserVO> findUser() {

        return platformBalanceLogDao.findUser();
    }

    @Override
    public List<UserCountVO> findUserCount() {

        return platformBalanceLogDao.findUserCount();
    }

    @Override
    public List<OfficeVO> findOffice() {
        return platformBalanceLogDao.findOffice();
    }

    @Override
    public List<OfficeCountVO> findOfficeCount() {
        return platformBalanceLogDao.findOfficeCount();
    }

    @Override
    public List<BalanceVO> findBalance() {
        return platformBalanceLogDao.findBalance();
    }

    @Override
    public List<BalanceCountVO> findBalanceCount() {
        return platformBalanceLogDao.findBalanceCount();
    }

    @Override
    public List<AdvVO> findAdv() {
        return platformBalanceLogDao.findAdv();
    }

    @Override
    public List<AdvCountVO> findAdvCount() {
        return platformBalanceLogDao.findAdvCount();
    }

}
